Skip to content

Fix Windows DLL loading for Python 3.8+#82

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/fix-srreal-dll-loading
Draft

Fix Windows DLL loading for Python 3.8+#82
Copilot wants to merge 4 commits intomainfrom
copilot/fix-srreal-dll-loading

Conversation

Copy link

Copilot AI commented Feb 11, 2026

What problem does this PR address?

Python 3.8+ restricts DLL loading on Windows to specific directories for security. Extension module srreal_ext cannot find dependencies (libdiffpy.dll, libObjCryst.dll, Boost, GSL) installed in %CONDA_PREFIX%\Library\bin, causing import failures.

What should the reviewer(s) do?

Review the Windows-specific initialization added to __init__.py and verify:

  • Logic only executes on Windows with Python 3.8+
  • No impact on Linux/macOS platforms
  • Test coverage is adequate

Changes:

  • src/diffpy/srreal/__init__.py: Add os.add_dll_directory() call for %CONDA_PREFIX%\Library\bin before extension imports
  • tests/test_dll_loading.py: Verify import succeeds and Windows DLL handling works across platforms

Example:

# Before: ImportError on Windows
from diffpy.srreal import pdfcalculator

# After: Imports successfully
from diffpy.srreal import pdfcalculator
pc = PDFCalculator()
Original prompt

This section details on the original issue you should resolve

<issue_title>srreal DLL not loading properly on windows</issue_title>
<issue_description>### Problem
I am getting this when I try and run tests in pdfbl-sequential on windows:

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    #!/usr/bin/env python
    ##############################################################################
    #
    # diffpy.srreal     by DANSE Diffraction group
    #                   Simon J. L. Billinge
    #                   (c) 2010 The Trustees of Columbia University
    #                   in the City of New York.  All rights reserved.
    #
    # File coded by:    Pavol Juhas
    #
    # See AUTHORS.txt for a list of people who contributed.
    # See LICENSE_DANSE.txt for license information.
    #
    ##############################################################################
    """
    Top-level classes for PDF calculation:
        DebyePDFCalculator -- simulate PDF by evaluating Debye sum in Q-space
        PDFCalculator      -- calculate PDF by peak summation in real space
    """

>   from diffpy.srreal.srreal_ext import (
        DebyePDFCalculator,
        PDFCalculator,
        fftftog,
        fftgtof,
    )
E   ImportError: DLL load failed while importing srreal_ext: The specified module could not be found.

..\..\micromamba\envs\pdfbl\Lib\site-packages\diffpy\srreal\pdfcalculator.py:21: ImportError
====================================================== short test summary info ======================================================
FAILED tests/test_pdfadapter.py::test_pdfadapter - ImportError: DLL load failed while importing srreal_ext: The specified module could not be found.
FAILED tests/test_sequential_cmi_runner.py::test_load_inputs_bad - ImportError: DLL load failed while importing srreal_ext: The specified module could not be found.
FAILED tests/test_sequential_cmi_runner.py::test_run_sequential_cmi_runner - ImportError: DLL load failed while importing srreal_ext: The specified module could not be found.
FAILED tests/test_sequential_cmi_runner.py::test_data_for_plot - ImportError: DLL load failed while importing srreal_ext: The specified module could not be found.
========================================================= 4 failed in 7.15s =========================================================

Proposed solution

Figure out why and fix it. Here is the env list:

List of packages in environment: "C:\\Users\\simon\\micromamba\\envs\\pdfbl"

  Name                Version       Build                  Channel
------------------------------------------------------------------------
  arrow               1.4.0         py312haa95532_0        pkgs/main
  bg-mpl-stylesheets  0.5.1         pyhff2d567_0           conda-forge
  binaryornot         0.4.4         pyhd3eb1b0_1           pkgs/main
  blas                1.0           mkl                    pkgs/main
  brotlicffi          1.2.0.0       py312h885b0b7_0        pkgs/main
  bzip2               1.0.8         h2bbff1b_6             pkgs/main
  ca-certificates     2025.12.2     haa95532_0             pkgs/main
  cairo               1.18.4        he9e932c_0             pkgs/main
  certifi             2026.01.04    py312haa95532_0        pkgs/main
  cffi                2.0.0         py312h02ab6af_1        pkgs/main
  cfgv                3.5.0         py312haa95532_0        pkgs/main
  chardet             5.2.0         py312haa95532_0        pkgs/main
  charset-normalizer  3.4.4         py312haa95532_0        pkgs/main
  click               8.2.1         py312haa95532_1        pkgs/main
  codecov             2.1.11        pyhd3eb1b0_0           pkgs/main
  colorama            0.4.6         py312haa95532_0        pkgs/main
  contourpy           1.3.3         py312h214f63a_0        pkgs/main
  cookiecutter        2.6.0         py312haa95532_1        pkgs/main
  coverage            7.11.0        py312h630b2a1_1        pkgs/main
  cycler              0.12.1        py312haa95532_0        pkgs/main
  diffpy.cmi          3.1.2         pyhd8ed1ab_0           conda-forge
  diffpy.srfit        3.2.0         pyhd8ed1ab_0           conda-forge
  diffpy.srreal       1.4.0         py312h0e1366e_3        conda-forge
  diffpy.structure    3.3.1         pyhd8ed1ab_0           conda-forge
  diffpy.utils        3.7.1         pyhd8ed1ab_0           conda-forge
  distlib             0.4.0         py312h02ab6af_0        pkgs/main
  dlfcn-win32         1.4.2         hac47afa_0             conda-forge
  expat               2.7.4         hd7fb8db_0             pkgs/main
  filelock            3.20.3        py312haa95532_0        pkgs/main
  flake8              7.3.0         py312haa95532_0        pkgs/main
  fontconfig          2.15.0        hd211d86_0             pkgs/main
  fonttools           4.61.0        py312h02ab6af_0        pkgs/main
  freetype            2....

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes diffpy/diffpy.srreal#81

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.

Copilot AI and others added 3 commits February 11, 2026 14:38
Co-authored-by: sbillinge <4254545+sbillinge@users.noreply.github.com>
Co-authored-by: sbillinge <4254545+sbillinge@users.noreply.github.com>
Co-authored-by: sbillinge <4254545+sbillinge@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix srreal DLL not loading properly on Windows Fix Windows DLL loading for Python 3.8+ Feb 11, 2026
Copilot AI requested a review from sbillinge February 11, 2026 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants